package com.nineclock.sign.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SalaryDTO;
import com.nineclock.sign.service.SalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;


@RestController
@Api(value = "薪资接口", tags = "签到服务")
@RequestMapping("/salary")
@Slf4j
public class SalaryController {
    @Autowired
    private SalaryService salaryService;

    /**
     * 查询员工薪资列表
     *
     * @param month
     * @param keyword
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/salary")
    @ApiOperation("查询员工薪资列表")
    public Result<PageResult<SalaryDTO>> salary(@RequestParam String month,
                                                @RequestParam(required = false) String keyword,
                                                @RequestParam(defaultValue = "1") Integer page,
                                                @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<SalaryDTO> result = salaryService.querySalary(month, keyword, page, pageSize);
        return Result.success(result);
    }

    /**
     * 薪资excel导出
     */
    @GetMapping("export")
    @ApiOperation("薪资excel导出")
    public void excelExport(String month) throws IOException {
        salaryService.excelExport(month);
    }
}
